import sys

class pySKFW():
	def pySKFWModuleImport(self):
		global pySKFWModuleMandatory
		print "Importing modules "
		result={'loaded':[],'mandatory':[],'unloaded':[]}
		for method in [method for method in dir(self) if method.startswith('import') ]:
			methodStr = method.replace('import','').lower()
			try:
				pySKFWModuleMandatory=True
				print "  - %s : " % methodStr,
				_member = getattr(self, method)
				_member()
				
			except ImportError as strerror:
				typeLoading = pySKFWModuleMandatory and 'mandatory' or 'unloaded'
				print "failed %s" % typeLoading
				result[typeLoading].append({'name':methodStr,'loaded':False,'raison':strerror})
			else:
				print "ok" 
				result['loaded'].append({'name':methodStr,'loaded':True})
		if len(result['mandatory']):
			print "################"
			for mod in result['mandatory']:
				print "%s failed due to %s"%(mod['name'],mod['raison'])
			sys.exit()
			
	def info(object, spacing=10, collapse=1):
		"""Print methods and doc strings.
		
		Takes module, class, list, dictionary, or string."""
		methodList = [method for method in dir(object) if callable(getattr(object, method))]
		processFunc = collapse and (lambda s: " ".join(s.split())) or (lambda s: s)
		print "\n".join(["%s %s" %
						  (method.ljust(spacing),
						   processFunc(str(getattr(object, method).__doc__)))
						 for method in methodList])    

    
